

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/avatar.gif">
  <link rel="icon" href="/img/avatar.gif">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="马振东">
  <meta name="keywords" content="Java,计算机,数据结构">
  
    <meta name="description" content="1. 下载安装 docker 和 compose，2.使用 3. 配置 4. docker 常用命令">
<meta property="og:type" content="article">
<meta property="og:title" content="docker安装常用中间件">
<meta property="og:url" content="https://bolg.plumdong.top/2023/03/19/docker%E5%AE%89%E8%A3%85%E5%B8%B8%E7%94%A8%E4%B8%AD%E9%97%B4%E4%BB%B6/index.html">
<meta property="og:site_name" content="PlumDong Bolg">
<meta property="og:description" content="1. 下载安装 docker 和 compose，2.使用 3. 配置 4. docker 常用命令">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://bolg.plumdong.top/image/pictures/dockerzhongjianjian.jpg">
<meta property="article:published_time" content="2023-03-18T16:00:00.000Z">
<meta property="article:modified_time" content="2023-03-20T01:52:32.265Z">
<meta property="article:author" content="马振东">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="docker">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://bolg.plumdong.top/image/pictures/dockerzhongjianjian.jpg">
  
  
  
  <title>docker安装常用中间件 - PlumDong Bolg</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"bolg.plumdong.top","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="PlumDong Bolg" type="application/atom+xml">
</head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 60vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>PlumDong Bolg</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="docker安装常用中间件"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-03-19 00:00" pubdate>
          2023年3月19日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          4.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          40 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">docker安装常用中间件</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="下载安装-docker-和-compose"><a href="#下载安装-docker-和-compose" class="headerlink" title="下载安装 docker 和 compose"></a>下载安装 docker 和 compose</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 安装docker</span><br>curl -sSL https://get.daocloud.io/docker | sh<br><span class="hljs-comment"># 启动docker</span><br>systemctl start docker.service<br><span class="hljs-comment"># 开启自启动</span><br>systemctl <span class="hljs-built_in">enable</span> docker<br><span class="hljs-comment"># Compose 安装</span><br>curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-`uname -s`-`uname -m` &gt; /usr/<span class="hljs-built_in">local</span>/bin/docker-compose<br><span class="hljs-comment"># 将可执行权限应用于二进制文件：</span><br>sudo chmod +x /usr/<span class="hljs-built_in">local</span>/bin/docker-compose<br><span class="hljs-comment"># 创建软链：</span><br>sudo ln -s /usr/<span class="hljs-built_in">local</span>/bin/docker-compose /usr/bin/docker-compose<br><span class="hljs-comment"># 测试是否安装成功：</span><br>docker compose version<br></code></pre></td></tr></table></figure>

<h1 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h1><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># 新建文件夹</span><br><span class="hljs-string">mkdir</span> <span class="hljs-string">compose</span><br><span class="hljs-comment"># 上传 docker-compose.yml 文件</span><br><span class="hljs-comment"># 在 docker-compose.yml 文件夹中 输入</span><br><span class="hljs-string">docker-compose</span> <span class="hljs-string">up</span> <span class="hljs-string">-d</span><br></code></pre></td></tr></table></figure>

<h2 id="docker-compose-yml-文件信息"><a href="#docker-compose-yml-文件信息" class="headerlink" title="docker-compose.yml 文件信息"></a>docker-compose.yml 文件信息</h2><p>以 mysql8，redis ，mongo 为例：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># 注意：所有持久化容器（MySQL、Redis、Elasticsearch）的Docker Compose文件禁止配置`# restart: always`；</span><br><span class="hljs-comment"># 否则可能导致反复重启，占用大量CPU与内存，导致死机，进而可能影响到物理机\n</span><br><span class="hljs-comment"># 一定要对容器资源进行限制</span><br><br><span class="hljs-attr">version:</span> <span class="hljs-string">&quot;3.8&quot;</span><br><span class="hljs-attr">services:</span><br>  <span class="hljs-comment">##########################################################################################################</span><br>  <span class="hljs-attr">mysql:</span><br>    <span class="hljs-attr">image:</span> <span class="hljs-string">mysql:8.0.30</span><br>    <span class="hljs-attr">container_name:</span> <span class="hljs-string">mysql</span><br>    <span class="hljs-comment"># hostname: mysql</span><br>    <span class="hljs-attr">command:</span> <span class="hljs-string">mysqld</span> <span class="hljs-string">--character-set-server=utf8mb4</span> <span class="hljs-string">--collation-server=utf8mb4_unicode_ci</span><br>    <span class="hljs-attr">environment:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">MYSQL_ROOT_PASSWORD=mima123?</span><br>    <span class="hljs-attr">ports:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-number">3306</span><span class="hljs-string">:3306</span><br>    <span class="hljs-attr">volumes:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/data/mysql/my.cnf/:/etc/my.cnf</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/data/mysql/data/:/var/lib/mysql</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/data/mysql/log/:/var/log/mysql</span><br>    <span class="hljs-comment"># restart: always</span><br>    <span class="hljs-comment"># 健康监测</span><br>    <span class="hljs-attr">healthcheck:</span><br>      <span class="hljs-attr">test:</span> [<span class="hljs-string">&quot;CMD&quot;</span>, <span class="hljs-string">&quot;mysqladmin&quot;</span>, <span class="hljs-string">&quot;ping&quot;</span>, <span class="hljs-string">&quot;-h&quot;</span>, <span class="hljs-string">&quot;localhost&quot;</span>]<br>      <span class="hljs-attr">interval:</span> <span class="hljs-string">5s</span><br>      <span class="hljs-attr">timeout:</span> <span class="hljs-string">10s</span><br>      <span class="hljs-attr">retries:</span> <span class="hljs-number">10</span><br><br>    <span class="hljs-comment"># # 资源限制</span><br>    <span class="hljs-attr">deploy:</span><br>      <span class="hljs-attr">resources:</span><br>        <span class="hljs-attr">limits:</span><br>          <span class="hljs-attr">cpus:</span> <span class="hljs-string">&quot;2&quot;</span><br>          <span class="hljs-attr">memory:</span> <span class="hljs-string">500M</span><br>        <span class="hljs-attr">reservations:</span><br>          <span class="hljs-attr">cpus:</span> <span class="hljs-string">&quot;0.5&quot;</span><br>          <span class="hljs-attr">memory:</span> <span class="hljs-string">100M</span><br><br>    <span class="hljs-comment"># 权限</span><br>    <span class="hljs-attr">privileged:</span> <span class="hljs-literal">true</span><br><br>  <span class="hljs-comment">##########################################################################################################</span><br><br>  <span class="hljs-attr">redis:</span><br>    <span class="hljs-attr">image:</span> <span class="hljs-string">docker.io/library/redis:latest</span><br>    <span class="hljs-attr">ports:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-number">6379</span><span class="hljs-string">:6379</span><br>    <span class="hljs-attr">container_name:</span> <span class="hljs-string">redis</span><br>    <span class="hljs-comment"># hostname: redis</span><br>    <span class="hljs-attr">volumes:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/data/redis/redis.conf:/usr/local/etc/redis/redis.conf</span><br>    <span class="hljs-attr">command:</span> <span class="hljs-string">redis-server</span> <span class="hljs-string">/usr/local/etc/redis/redis.conf</span><br><br>    <span class="hljs-comment"># # 资源限制</span><br>    <span class="hljs-attr">deploy:</span><br>      <span class="hljs-attr">resources:</span><br>        <span class="hljs-attr">limits:</span><br>          <span class="hljs-attr">cpus:</span> <span class="hljs-string">&quot;1&quot;</span><br>          <span class="hljs-attr">memory:</span> <span class="hljs-string">500M</span><br>        <span class="hljs-attr">reservations:</span><br>          <span class="hljs-attr">cpus:</span> <span class="hljs-string">&quot;0.5&quot;</span><br>          <span class="hljs-attr">memory:</span> <span class="hljs-string">100M</span><br><br>    <span class="hljs-comment"># 权限</span><br>    <span class="hljs-attr">privileged:</span> <span class="hljs-literal">true</span><br><br>  <span class="hljs-attr">mongo-server:</span><br>    <span class="hljs-attr">container_name:</span> <span class="hljs-string">mongo</span><br>    <span class="hljs-attr">image:</span> <span class="hljs-string">mongo:latest</span><br>    <span class="hljs-attr">environment:</span><br>      <span class="hljs-attr">MONGO_INITDB_ROOT_USERNAME:</span> <span class="hljs-string">root</span><br>      <span class="hljs-attr">MONGO_INITDB_ROOT_PASSWORD:</span> <span class="hljs-string">mima123?</span><br>    <span class="hljs-attr">ports:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-number">27017</span><span class="hljs-string">:27017</span><br>    <span class="hljs-attr">volumes:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/etc/localtime:/etc/localtime</span> <span class="hljs-comment"># 时区</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/data/mongo/mongo-server/data:/data/db</span> <span class="hljs-comment"># 挂载数据目录</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">/data/mongo/mongo-server/log:/var/log/mongodb</span> <span class="hljs-comment"># 挂载日志目录</span><br>    <span class="hljs-comment">#  - /data/mongo/mongo-server/config:/etc/mongo  # 挂载配置目录</span><br><br>    <span class="hljs-comment"># # 资源限制</span><br>    <span class="hljs-attr">deploy:</span><br>      <span class="hljs-attr">resources:</span><br>        <span class="hljs-attr">limits:</span><br>          <span class="hljs-attr">cpus:</span> <span class="hljs-string">&quot;2&quot;</span><br>          <span class="hljs-attr">memory:</span> <span class="hljs-string">500M</span><br>        <span class="hljs-attr">reservations:</span><br>          <span class="hljs-attr">cpus:</span> <span class="hljs-string">&quot;0.5&quot;</span><br>          <span class="hljs-attr">memory:</span> <span class="hljs-string">100M</span><br><br>    <span class="hljs-comment"># 权限</span><br>    <span class="hljs-attr">privileged:</span> <span class="hljs-literal">true</span><br></code></pre></td></tr></table></figure>

<h1 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h1><h2 id="Mysql8-配置"><a href="#Mysql8-配置" class="headerlink" title="Mysql8 配置"></a>Mysql8 配置</h2><h3 id="1-设置启动-docker-时，即运行-mysql"><a href="#1-设置启动-docker-时，即运行-mysql" class="headerlink" title="1. 设置启动 docker 时，即运行 mysql"></a>1. 设置启动 docker 时，即运行 mysql</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">[root@hadoop-104 ~]<span class="hljs-comment"># docker update mysql --restart=always</span><br></code></pre></td></tr></table></figure>

<h3 id="2-限制-mysql8-内存"><a href="#2-限制-mysql8-内存" class="headerlink" title="2. 限制 mysql8 内存"></a>2. 限制 mysql8 内存</h3><p>修改配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs bash">[mysqld]<br>performance_schema_max_table_instances=400 <span class="hljs-comment">#设置效果不明显</span><br>table_definition_cache=400 <span class="hljs-comment">#缓存</span><br>performance_schema=off     <span class="hljs-comment">#效果明显 , 用于监控MySQL server在一个较低级别的运行过程中的资源消耗、资源东西</span><br>table_open_cache=64       <span class="hljs-comment"># #打开表的缓存</span><br>innodb_buffer_pool_chunk_size=64M <span class="hljs-comment">#效果不明显  #InnoDB缓冲池大小调整操作的块大小</span><br>innodb_buffer_pool_size=64M <span class="hljs-comment">#效果不明显  #InnoDB 存储引擎的表数据和索引数据的最大内存缓冲区大小</span><br></code></pre></td></tr></table></figure>

<p>查看修改后的内存情况 : <code>docker stats</code></p>
<h3 id="3-设置-root-用户远程访问"><a href="#3-设置-root-用户远程访问" class="headerlink" title="3. 设置 root 用户远程访问"></a>3. 设置 root 用户远程访问</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 进入mysql 容器</span><br>docker <span class="hljs-built_in">exec</span> -it mysql /bin/bash<br><span class="hljs-comment"># 连接 mysql</span><br>mysql -uroot -p<br><span class="hljs-comment"># 选择数据库</span><br>use mysql;<br><span class="hljs-comment"># 在 mysql 数据库的 user 表中查看当前 root 用户的相关信息</span><br>select host, user, authentication_string, plugin from user;<br><span class="hljs-comment"># 授权 root 用户的所有权限并设置远程访问</span><br>update user <span class="hljs-built_in">set</span> host=<span class="hljs-string">&#x27;%&#x27;</span> <span class="hljs-built_in">where</span> user=<span class="hljs-string">&#x27;root&#x27;</span>;<br>GRANT ALL ON *.* TO <span class="hljs-string">&#x27;root&#x27;</span>@<span class="hljs-string">&#x27;%&#x27;</span>;<br><br><span class="hljs-comment"># 更新 root 用户密码 为：root</span><br>ALTER USER <span class="hljs-string">&#x27;root&#x27;</span>@<span class="hljs-string">&#x27;%&#x27;</span> IDENTIFIED WITH mysql_native_password BY <span class="hljs-string">&#x27;root&#x27;</span>;<br><br><span class="hljs-comment"># 刷新权限</span><br>flush privileges;<br><span class="hljs-comment"># 重启mysql</span><br></code></pre></td></tr></table></figure>

<h2 id="Mongo-配置"><a href="#Mongo-配置" class="headerlink" title="Mongo 配置"></a>Mongo 配置</h2><h3 id="1-设置启动-docker-时，即运行-mongo"><a href="#1-设置启动-docker-时，即运行-mongo" class="headerlink" title="1. 设置启动 docker 时，即运行 mongo"></a>1. 设置启动 docker 时，即运行 mongo</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">[root@hadoop-104 ~]<span class="hljs-comment"># docker update mongo --restart=always</span><br></code></pre></td></tr></table></figure>

<h3 id="2-创建用户"><a href="#2-创建用户" class="headerlink" title="2. 创建用户"></a>2. 创建用户</h3><p>登录 mongo 容器，并进入到【admin】数据库</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs bash">docker <span class="hljs-built_in">exec</span> -it mongo mongosh admin<br><span class="hljs-comment"># 登录 root 用户</span><br>db.auth(<span class="hljs-string">&#x27;root&#x27;</span>,<span class="hljs-string">&#x27;mima123??&#x27;</span>)<br><span class="hljs-comment"># 创建数据库，</span><br>use demodb<br><span class="hljs-comment"># 创建用户 admin 注意root用户没有操作其他数据的权限，必须新建一个用户，并且用户和数据库是绑定关系</span><br>db.createUser(&#123;user: <span class="hljs-string">&quot;admin&quot;</span>, <span class="hljs-built_in">pwd</span>: <span class="hljs-string">&quot;mima123??&quot;</span>, roles: [&#123; role: <span class="hljs-string">&quot;dbOwner&quot;</span>, db: <span class="hljs-string">&quot;demodb&quot;</span> &#125;]&#125;);<br><span class="hljs-comment"># 切换到 用户 admin</span><br>db.auth(<span class="hljs-string">&#x27;admin&#x27;</span>,<span class="hljs-string">&#x27;mima123??&#x27;</span>)<br><span class="hljs-comment"># 插入一条数据</span><br>db.user.insert(&#123;<span class="hljs-string">&quot;name&quot;</span>:<span class="hljs-string">&quot;我叫123&quot;</span>&#125;)<br><span class="hljs-comment"># 查看数据</span><br>db.user.find()<br></code></pre></td></tr></table></figure>

<h3 id="3-navcat-连接"><a href="#3-navcat-连接" class="headerlink" title="3.navcat 连接"></a>3.navcat 连接</h3><p><img src="/articleimages/docker%20%E5%AE%89%E8%A3%85%E5%B8%B8%E7%94%A8%E4%B8%AD%E9%97%B4%E4%BB%B6%207518f132bf5f43cbb43e5e9c7bd287c8/Untitled.png" srcset="/img/loading.gif" lazyload alt="Untitled"></p>
<h3 id="4-mongo-其他命令"><a href="#4-mongo-其他命令" class="headerlink" title="4. mongo 其他命令"></a>4. mongo 其他命令</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 查看当前数据库中的所有用户</span><br>db.getUsers()<br><span class="hljs-comment"># 查看所有数据库</span><br>show dbs<br><br><span class="hljs-comment"># 新建副本集 TODO</span><br>rs.initiate(<br>   &#123;<br>      _id: <span class="hljs-string">&quot;myReplSet&quot;</span>,<br>      members: [<br>         &#123; _id: 0, host : <span class="hljs-string">&quot;8.219.228.60:27017&quot;</span> &#125;<br>      ]<br>   &#125;<br>)<br>db.createUser(&#123;user: <span class="hljs-string">&quot;admin&quot;</span>, <span class="hljs-built_in">pwd</span>: <span class="hljs-string">&quot;123456aA?&quot;</span>, roles: [&#123; role: <span class="hljs-string">&quot;dbOwner&quot;</span>, db: <span class="hljs-string">&quot;demo&quot;</span> &#125;]&#125;);<br>db.auth(<span class="hljs-string">&#x27;admin&#x27;</span>,<span class="hljs-string">&#x27;123456aA?&#x27;</span>)<br><br>db.user.insert(&#123;<span class="hljs-string">&quot;name&quot;</span>:<span class="hljs-string">&quot;我叫123&quot;</span>&#125;)<br><br>db.updateUser(<span class="hljs-string">&quot;admin&quot;</span>,&#123;db: <span class="hljs-string">&quot;demo&quot;</span> &#125;)<br></code></pre></td></tr></table></figure>

<h1 id="docker-常用命令"><a href="#docker-常用命令" class="headerlink" title="docker 常用命令"></a>docker 常用命令</h1><h2 id="查询-近-100-行日志"><a href="#查询-近-100-行日志" class="headerlink" title="查询 近 100 行日志"></a>查询 近 100 行日志</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">docker logs -f -t  --tail=100 CONTAINER_ID<br></code></pre></td></tr></table></figure>

<h2 id="查看某个时间之后的日志"><a href="#查看某个时间之后的日志" class="headerlink" title="查看某个时间之后的日志"></a>查看某个时间之后的日志</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">docker logs -t --since=<span class="hljs-string">&quot;2018-02-08&quot;</span> CONTAINER_ID<br></code></pre></td></tr></table></figure>

<h2 id="限制容器内存"><a href="#限制容器内存" class="headerlink" title="限制容器内存"></a>限制容器内存</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">docker run --name mongo -m 100M --memory-swap -1 -d mongo<br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/docker/" class="category-chain-item">docker</a>
  
  
    <span>></span>
    
  <a href="/categories/docker/linux/" class="category-chain-item">linux</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/linux/">#linux</a>
      
        <a href="/tags/docker/">#docker</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>docker安装常用中间件</div>
      <div>https://bolg.plumdong.top/2023/03/19/docker安装常用中间件/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>马振东</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年3月19日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/03/18/%E7%BA%A2%E9%BB%91%E6%A0%91/" title="红黑树">
                        <span class="hidden-mobile">红黑树</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
